<!--
Author: XiaoWen
Create a file: 2016-12-07 10:09:27
Last modified: 2016-12-07 10:21:28
Start to work:
Finish the work:
Other information:
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>点击显示和隐藏</title>
  <style>
    div{
      width: 100px;
      height: 100px;
      background: #eee;
    }
  </style>
</head>
<body>
  <button>
    显示/隐藏
  </button>
  <div>受罪的div，想隐藏就隐藏</div>
  <script>
    var but=document.getElementsByTagName("button");
    var div=document.getElementsByTagName("div");
    var temp=0; //0为显示
    but[0].onclick=function(){
      if(temp==0){ //本来是显示的，所以就隐藏咯
        div[0].style="display:none";
        temp=1; //隐藏了就把状态改变了
      }else{
        div[0].style="display:block";
        temp=0;
      }
    }
  </script>
</body>
</html>